Skip to content

DEV-1266: Android HIL queueStress, to reproduce the lock-order deadlock - #136

Merged
JongChern merged 3 commits into
DEV-1291_android_hil_scenariosfrom
DEV-1266_android_hil_queue_stress
Oct 23, 2026
Merged

JongChern merged 3 commits into
DEV-1291_android_hil_scenariosfrom
DEV-1266_android_hil_queue_stress

Conversation

@JongChern

Copy link
Copy Markdown
Contributor

DEV-1266. A new Android HIL scenario, queueStress, that reproduces the driver's lock-order deadlock on demand, so #135's driver bump can be shown to fix it on Android. Stacked on #134; merge #128 and #134 first.

Why a new scenario

The driver guards its instruction queue with two locks, the device and the queue. Up to 0.11.10_beta its IO thread took them queue first when fetching the next instruction, while every call that queues an instruction takes them device first. The two could deadlock, and every later call hung. On Android this hung 5 of 12 inStream runs on driver 0.11.7_beta, but inStream needs SD logging and only catches it by chance.

queueStress widens the window on purpose, as the Java HIL's scenario of the same name does. With the unit connected and idle, timers on, four threads queue battery and status reads in tight loops for 60 s, keeping the queue under 8. It runs idle because, while streaming, Android writes these reads straight out, unqueued, so they never take the queue's lock. It needs no SD card, so it runs on a docked or charging unit too.

It fails when a read doesn't return within 10 s, no read returns for 10 s, or the queue doesn't drain within 15 s after the reads stop; each of these puts every thread's stack in the events. It also fails when a read throws. The runner runs it by default and the README lists it.

Tested on the bench

Phone M2101K6G (Android 11). s3-3e36 is a Shimmer3, LogAndStream v1.1.7, over Classic; s3r-2f31 is a Shimmer3R, v1.1.22, over BLE. The link CRC was 1 byte. The library build was this branch merged with #122, #132, #133, #134 and #135.

Driver s3-3e36, Classic s3r-2f31, BLE
0.11.7_beta (master's pin) deadlocked, 2 of 2 runs, after 240 and about 570 reads deadlocked, 1 of 1 run, after 323 reads
0.11.11_beta (#135) passed 2 of 2: 556 and 565 reads, queue drained passed 2 of 2: 426 and 420 reads, queue drained

Every deadlock's thread dump is DEV-1266's signature:

  • the IO thread is BLOCKED in getInstruction() → getListofInstructions(), holding the queue and waiting for the device;
  • the reading threads are BLOCKED in writeInstruction(), holding the device and waiting for the queue;
  • the status timer is BLOCKED behind them.

🤖 Generated with Claude Code

The driver guards its instruction queue with two locks, the device and the
queue. Up to 0.11.10_beta its IO thread took them queue first when it
fetched the next instruction, and every call that queues one takes them
device first, so the two could deadlock and every later call hung. On
Android it hung 5 of 12 inStream runs on driver 0.11.7_beta, but inStream
needs SD logging and catches it only by chance.

queueStress makes the window wide on purpose, as the Java HIL's scenario of
the same name does. With the unit connected and idle, timers on, four
threads queue battery and status reads in tight loops for 60 s, keeping the
queue under 8. Idle, because while streaming Android writes these reads
straight out, unqueued, and they never take the queue's lock. It needs no
SD card, so it also runs on a docked or charging unit.

It fails when a read doesn't return within 10 s or no read returns for 10 s,
with every thread's stack in the events; when a read throws; or when the
queue doesn't drain within 15 s. The runner runs it by default and the
README lists it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Up to driver 0.11.10_beta, a configuration written straight after
stopStreaming() could lose its first chunk, the one holding the sampling
rate: operationPrepare() cleared the instruction list while the STOP was
still in flight, and the stop's reply then retired the next instruction in
its place. The unit kept its old rate. The Java HIL's samplingRates found it
on a Shimmer3 and a Shimmer3R. Android configures through the same driver
code over both transports, and had no scenario for it.

samplingRates, as in the Java and shimmer-logandstream HILs, writes 51.2, 256
and 512 Hz in turn and streams 5 s at each, then writes the unit's own rate
back; every configure but the first comes straight after a stop. Unlike the
Java HIL's configure, the Android one can finish on the manager's SUCCESS
without looking at the rate, so the scenario checks that the rate read back
is the one written. No SD card is needed. The runner runs it by default and
the README lists it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pling_rates

DEV-1306: Android HIL samplingRates, configuring straight after a stop
@JongChern
JongChern merged commit 7c16b8a into DEV-1291_android_hil_scenarios Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant